<template>
  <div>
  <h2>管理员登陆</h2>
    <table class="table table-bordered">
      <tbody>
      <tr>
        <td align="right">账号</td>
        <td>
          <input type="text" v-model="info.username">
        </td>
      </tr>
      <tr>
        <td align="right">密码</td>
        <td>
          <input type="password" v-model="info.userpwd">
        </td>
      </tr>
      <tr>
        <td align="right"></td>
        <td>
          <input type="button" value="登陆" class="btn btn-primary" @click="login">
        </td>
      </tr>
      </tbody>
    </table>
  </div>
  {{info}}
</template>

<script setup lang="ts">
import {ref,reactive,onMounted} from 'vue'
import {useRouter} from 'vue-router'
import axios from "axios";
const router = useRouter()

let info:any = reactive({
  username:'',
  userpwd:''
})

const login = () => {
  if(info.username === ''){
    alert('账号不能为空');
    return;
  }
  if(info.userpwd === ''){
    alert('密码不能为空');
    return;
  }

  axios({
    url:'/api/Admins/Login',
    method:'get',
    params:info
  })
      .then((res) => {
        console.log(res)
        if(res.data==-1){
          alert('没有该账号');
          return;
        }
        if(res.data==-2){
          alert('密码错误');
          return;
        }
        alert('登陆成功');
        router.push('/adminAdd')
      })
  .catch((err)=>{
    console.log(err)
  })
}
</script>

<style scoped>

</style>